{% extends "score/base.html" %}
{% load static %}

{% block title %}{{ title }} - ExamPulse{% endblock %}

{% block extra_css %}
    <link rel="stylesheet" href="{% static 'score/css/score_form.css' %}">
    <style>
        /* 三列网格布局 */
        .form-grid.three-columns {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 1.5rem;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .form-grid.three-columns {
                grid-template-columns: 1fr;
            }
        }

        /* 编辑模式只读字段样式 */
        .readonly-field {
            background-color: #f8f9fa;
            cursor: not-allowed;
            opacity: 0.8;
        }

        /* 可编辑字段样式 */
        .editable-field {
            background-color: white;
            cursor: text;
        }
    </style>
{% endblock %}

{% block extra_js %}
    <!-- 科目数据 -->
    <script id="subject-data" type="application/json">
        {
        {% for subject in subjects %}
            "{{ subject.name|escapejs }}": {
        "name": "{{ subject.name|escapejs }}",
        "full_score": {{ subject.full_score }},
        "color": "{{ subject.color|escapejs }}"
    }{% if not forloop.last %},{% endif %}
    {% endfor %}
        }
    </script>
    <script src="{% static 'score/js/score_form.js' %}"></script>
{% endblock %}

{% block score_content %}
    <div class="score-form-container">
        <!-- 页面标题 -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="page-title">
                <i class="fas {% if is_edit %}fa-edit{% else %}fa-plus-circle{% endif %} text-primary me-2"></i>{{ title }}
            </h2>
            <a href="

                    {% if is_edit %}{% if is_admin %}{% url 'score:score_list' %}{% else %}{% url 'score:score_detail' pk=exam_record.pk %}{% endif %}{% else %}{% url 'score:score_list' %}{% endif %}"
               class="btn btn-outline-custom">
                <i class="fas fa-arrow-left me-2"></i>返回{% if is_edit %}{% if is_admin %}列表{% else %}
                详情{% endif %}{% else %}列表{% endif %}
            </a>
        </div>

        <!-- 调试信息 -->
        {% if debug %}
            <div class="debug-info">
                <small class="text-muted">
                    调试信息:
                    模式: {% if is_edit %}编辑{% else %}添加{% endif %} |
                    显示学生选择: {% if show_student_selection %}是{% else %}否{% endif %} |
                    是管理员: {% if is_admin %}是{% else %}否{% endif %} |
                    有学生: {% if student %}是{% else %}否{% endif %} |
                    有选中学生: {% if selected_student %}是{% else %}否{% endif %} |
                    表单字段: {% if form %}{{ form.fields.keys|join:", " }}{% else %}无表单{% endif %}
                </small>
            </div>
        {% endif %}

        <!-- 学生选择页面（管理员模式 - 仅添加时显示） -->
        {% if not is_edit and show_student_selection %}
            <div class="form-section">
                <div class="section-header">
                    <div class="section-icon exam">
                        <i class="fas fa-user-graduate"></i>
                    </div>
                    <h3 class="section-title">选择学生</h3>
                </div>

                {% if not students %}
                    <div class="alert alert-warning">
                        <i class="fas fa-exclamation-triangle me-2"></i>
                        系统中暂无学生数据，请先创建学生信息。
                    </div>
                {% else %}
                    <form method="get" id="studentSelectionForm">
                        <div class="student-selection-grid">
                            {% for student in students %}
                                <div class="student-card" onclick="selectStudent('{{ student.id }}')">
                                    <div class="d-flex align-items-start">
                                        <div class="student-avatar-large">
                                            {{ student.name|first }}
                                        </div>
                                        <div class="student-info">
                                            <div class="student-name">{{ student.name }}</div>
                                            <div class="student-meta">
                                                {{ student.target_school|default:"未设置目标院校" }}
                                                {% if student.target_major %}
                                                    · {{ student.target_major }}
                                                {% endif %}
                                            </div>
                                            <div class="student-meta">
                                                {{ student.attempt_count }} · {{ student.postgraduate_status }}
                                            </div>

                                            <!-- 学生考试科目 -->
                                            <div class="student-subjects">
                                                {% if student.has_politics %}
                                                    <span class="subject-tag">政治</span>
                                                {% endif %}
                                                {% if student.has_english and student.english_type != '不考' %}
                                                    <span class="subject-tag">{{ student.english_type }}</span>
                                                {% endif %}
                                                {% if student.has_math and student.math_type != '不考' %}
                                                    <span class="subject-tag">{{ student.math_type }}</span>
                                                {% endif %}
                                                {% if student.professional_subject_name %}
                                                    <span class="subject-tag">{{ student.professional_subject_name }}</span>
                                                {% endif %}
                                                {% if student.has_professional_2 and student.professional_subject_2_name %}
                                                    <span class="subject-tag">{{ student.professional_subject_2_name }}</span>
                                                {% endif %}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            {% endfor %}
                        </div>

                        <input type="hidden" name="student_id" id="selectedStudentId">

                        <div class="selection-actions">
                            <button type="submit" class="btn btn-primary-custom" id="continueBtn" disabled>
                                <i class="fas fa-arrow-right me-2"></i>继续添加成绩
                            </button>
                        </div>
                    </form>
                {% endif %}
            </div>

        {% else %}
            <!-- 成绩表单页面 -->
            <form method="post" id="scoreForm" novalidate {% if is_edit %}class="edit-mode"{% endif %}>
                {% csrf_token %}

                <!-- 管理员模式：显示当前学生信息（仅添加时显示） -->
                {% if not is_edit and is_admin and selected_student %}
                    <input type="hidden" name="student_id" value="{{ selected_student.id }}">

                    <div class="form-section">
                        <div class="section-header">
                            <div class="section-icon exam">
                                <i class="fas fa-user-graduate"></i>
                            </div>
                            <h3 class="section-title">当前学生</h3>
                        </div>

                        <div class="alert alert-info">
                            <div class="d-flex align-items-center">
                                <div class="student-avatar me-3">
                                    {{ selected_student.name|first }}
                                </div>
                                <div>
                                    <strong>{{ selected_student.name }}</strong>
                                    <div class="small">
                                        {{ selected_student.target_school|default:"未设置目标院校" }}
                                        {% if selected_student.target_major %}
                                            · {{ selected_student.target_major }}
                                        {% endif %}
                                        · {{ selected_student.attempt_count }}
                                    </div>
                                </div>
                                <div class="ms-auto">
                                    <a href="{% url 'score:score_add' %}" class="btn btn-sm btn-outline-secondary">
                                        <i class="fas fa-redo me-1"></i>重新选择学生
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                {% endif %}

                <!-- 编辑模式：显示基本信息 -->
                {% if is_edit %}
                    <div class="form-section">
                        <div class="section-header">
                            <div class="section-icon exam">
                                <i class="fas fa-info-circle"></i>
                            </div>
                            <h3 class="section-title">基本信息</h3>
                        </div>
                        <div class="alert alert-info">
                            <div class="row">
                                <div class="col-md-6">
                                    <strong>学生:</strong> {{ exam_record.student.name }}
                                </div>
                                <div class="col-md-6">
                                    <strong>考试:</strong> {{ exam_record.exam.full_name }}
                                </div>
                                <div class="col-md-6">
                                    <strong>科目:</strong> {{ exam_record.subject.name }}
                                </div>
                                <div class="col-md-6">
                                    <strong>当前分数:</strong> {{ exam_record.score }}
                                    / {{ exam_record.subject.full_score }}
                                </div>
                            </div>
                        </div>
                    </div>
                {% endif %}

                <!-- 考试信息部分 -->
                <div class="form-section">
                    <div class="section-header">
                        <div class="section-icon exam">
                            <i class="fas fa-book"></i>
                        </div>
                        <h3 class="section-title">考试信息</h3>
                    </div>

                    <!-- 用户考试科目配置信息 -->
                    {% if not is_edit and is_admin and selected_student %}
                        <div class="alert alert-info mb-3">
                            <h6 class="alert-heading">
                                <i class="fas fa-info-circle me-2"></i>{{ selected_student.name }}的考试科目配置
                            </h6>
                            <div class="row small mt-2">
                                {% if selected_student.has_politics %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>政治
                                    </div>
                                {% endif %}
                                {% if selected_student.has_english and selected_student.english_type != '不考' %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ selected_student.english_type }}
                                    </div>
                                {% endif %}
                                {% if selected_student.has_math and selected_student.math_type != '不考' %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ selected_student.math_type }}
                                    </div>
                                {% endif %}
                                {% if selected_student.professional_subject_name %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ selected_student.professional_subject_name }}
                                    </div>
                                {% endif %}
                                {% if selected_student.has_professional_2 and selected_student.professional_subject_2_name %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ selected_student.professional_subject_2_name }}
                                    </div>
                                {% endif %}
                            </div>
                        </div>
                    {% elif not is_edit and not is_admin and student %}
                        <div class="alert alert-info mb-3">
                            <h6 class="alert-heading">
                                <i class="fas fa-info-circle me-2"></i>您的考试科目配置
                            </h6>
                            <div class="row small mt-2">
                                {% if student.has_politics %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>政治
                                    </div>
                                {% endif %}
                                {% if student.has_english and student.english_type != '不考' %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ student.english_type }}
                                    </div>
                                {% endif %}
                                {% if student.has_math and student.math_type != '不考' %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ student.math_type }}
                                    </div>
                                {% endif %}
                                {% if student.professional_subject_name %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ student.professional_subject_name }}
                                    </div>
                                {% endif %}
                                {% if student.has_professional_2 and student.professional_subject_2_name %}
                                    <div class="col-md-3 mb-1">
                                        <i class="fas fa-check text-success me-1"></i>{{ student.professional_subject_2_name }}
                                    </div>
                                {% endif %}
                            </div>
                        </div>
                    {% endif %}

                    <!-- 第一行：考试选择、基础名称、序号 -->
                    <div class="form-grid three-columns">
                        <!-- 考试选择 -->
                        <div class="form-group">
                            <label for="{{ form.exam.id_for_label }}" class="form-label">
                                <i class="fas fa-calendar-alt me-2"></i>选择考试
                            </label>
                            {% if is_edit %}
                                <!-- 编辑模式：显示考试名称，不可修改 -->
                                <input type="text" class="form-control readonly-field"
                                       value="{{ exam_record.exam.full_name }}" readonly>
                                <input type="hidden" name="exam" value="{{ exam_record.exam.id }}">
                            {% else %}
                                {{ form.exam }}
                            {% endif %}
                            {% if form.exam.errors %}
                                <div class="error-message">
                                    {% for error in form.exam.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">
                                {% if is_edit %}编辑模式下考试不可修改{% else %}选择之前参加过的考试{% endif %}
                            </div>
                        </div>

                        <!-- 自定义考试基础名称 -->
                        <div class="form-group">
                            <label for="{{ form.custom_exam_base_name.id_for_label }}" class="form-label">
                                <i class="fas fa-edit me-2"></i>考试基础名称
                            </label>
                            {% if is_edit %}
                                <!-- 编辑模式：显示基础名称，不可修改 -->
                                <input type="text" class="form-control readonly-field"
                                       value="{{ exam_record.exam.base_name }}" readonly>
                                <input type="hidden" name="custom_exam_base_name"
                                       value="{{ exam_record.exam.base_name }}">
                            {% else %}
                                {{ form.custom_exam_base_name }}
                            {% endif %}
                            {% if form.custom_exam_base_name.errors %}
                                <div class="error-message">
                                    {% for error in form.custom_exam_base_name.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">
                                {% if is_edit %}编辑模式下不可添加新考试{% else %}如：历年真题、张宇八套卷{% endif %}
                            </div>
                        </div>

                        <!-- 序号 -->
                        <div class="form-group">
                            <label for="{{ form.custom_exam_sequence.id_for_label }}" class="form-label">
                                <i class="fas fa-hashtag me-2"></i>序号
                            </label>
                            {% if is_edit %}
                                <!-- 编辑模式：显示序号，不可修改 -->
                                <input type="text" class="form-control readonly-field"
                                       value="{{ exam_record.exam.sequence_number }}" readonly>
                                <input type="hidden" name="custom_exam_sequence"
                                       value="{{ exam_record.exam.sequence_number }}">
                            {% else %}
                                {{ form.custom_exam_sequence }}
                            {% endif %}
                            {% if form.custom_exam_sequence.errors %}
                                <div class="error-message">
                                    {% for error in form.custom_exam_sequence.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">
                                {% if is_edit %}编辑模式下序号不可修改{% else %}数字，如：2006、6{% endif %}
                            </div>
                        </div>
                    </div>

                    <!-- 第二行：考试日期、科目选择 -->
                    <div class="form-grid">
                        <!-- 考试日期 -->
                        <!-- 考试日期 -->
                        <div class="form-group">
                            <label for="{{ form.exam_date.id_for_label }}" class="form-label">
                                <i class="fas fa-calendar me-2"></i>考试日期
                            </label>
                            {{ form.exam_date }}
                            {% if form.exam_date.errors %}
                                <div class="error-message">
                                    {% for error in form.exam_date.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">
                                {% if is_edit %}可修改考试日期（会更新考试的日期）{% else %}
                                    输入新考试时必须填写{% endif %}
                            </div>
                        </div>

                        <!-- 科目选择 -->
                        <div class="form-group">
                            <label for="{{ form.subject.id_for_label }}" class="form-label">
                                <i class="fas fa-graduation-cap me-2"></i>考试科目
                            </label>
                            {% if is_edit %}
                                <!-- 编辑模式：显示科目名称，不可修改 -->
                                <input type="text" class="form-control readonly-field"
                                       value="{{ exam_record.subject.name }}" readonly>
                                <input type="hidden" name="subject" value="{{ exam_record.subject.name }}">
                            {% else %}
                                {{ form.subject }}
                            {% endif %}
                            {% if form.subject.errors %}
                                <div class="error-message">
                                    {% for error in form.subject.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">
                                {% if is_edit %}编辑模式下科目不可修改{% else %}选择考试科目{% endif %}
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 成绩信息部分 -->
                <div class="form-section">
                    <div class="section-header">
                        <div class="section-icon score">
                            <i class="fas fa-chart-line"></i>
                        </div>
                        <h3 class="section-title">成绩信息</h3>
                    </div>

                    <!-- 第一行：科目总分、考试成绩 -->
                    <div class="form-grid">
                        <div class="form-group">
                            <label for="subject_total_score" class="form-label">
                                <i class="fas fa-chart-bar me-2"></i>科目总分
                            </label>
                            {% if is_edit %}
                                <!-- 编辑模式：显示科目总分，不可修改 -->
                                <input type="number" class="form-control readonly-field"
                                       value="{{ exam_record.subject.full_score }}" readonly>
                            {% else %}
                                <input type="number" class="form-control" id="subject_total_score"
                                       name="subject_total_score"
                                       step="0.5" min="0" value="{{ exam_record.subject.full_score|default:150 }}"
                                       required>
                            {% endif %}
                            <div class="form-text">该科目的满分分数</div>
                        </div>

                        <div class="form-group">
                            <label for="{{ form.score.id_for_label }}" class="form-label">
                                <i class="fas fa-star me-2"></i>考试成绩
                            </label>
                            {{ form.score }}
                            {% if form.score.errors %}
                                <div class="error-message">
                                    {% for error in form.score.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">请输入0-科目总分之间的分数</div>
                        </div>
                    </div>

                    <!-- 第二行：理想分数、考试用时 -->
                    <div class="form-grid">
                        <div class="form-group">
                            <label for="{{ form.target_score.id_for_label }}" class="form-label">
                                <i class="fas fa-bullseye me-2"></i>理想分数
                            </label>
                            {{ form.target_score }}
                            {% if form.target_score.errors %}
                                <div class="error-message">
                                    {% for error in form.target_score.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">期望达到的分数（可选）</div>
                        </div>

                        <div class="form-group">
                            <label for="{{ form.exam_duration.id_for_label }}" class="form-label">
                                <i class="fas fa-clock me-2"></i>考试用时
                            </label>
                            {{ form.exam_duration }}
                            {% if form.exam_duration.errors %}
                                <div class="error-message">
                                    {% for error in form.exam_duration.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">单位：分钟（可选）</div>
                        </div>
                    </div>

                    <!-- 第三行：题目完成度、难度系数 -->
                    <div class="form-grid">
                        <div class="form-group">
                            <label for="{{ form.question_completion.id_for_label }}" class="form-label">
                                <i class="fas fa-tasks me-2"></i>题目完成度
                            </label>
                            {{ form.question_completion }}
                            {% if form.question_completion.errors %}
                                <div class="error-message">
                                    {% for error in form.question_completion.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">0-100%（可选）</div>
                            <div class="progress mt-2" style="height: 6px;">
                                <div id="completionProgress" class="progress-bar" role="progressbar"
                                     style="width: 0%"></div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="{{ form.difficulty_level.id_for_label }}" class="form-label">
                                <i class="fas fa-balance-scale me-2"></i>难度系数
                            </label>
                            {{ form.difficulty_level }}
                            {% if form.difficulty_level.errors %}
                                <div class="error-message">
                                    {% for error in form.difficulty_level.errors %}{{ error }}{% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">0-10之间，数字越大难度越高（可选）</div>
                            <!-- 难度系数可视化指示器 -->
                            <div class="mt-2">
                                <div class="difficulty-indicator">
                                    <div class="difficulty-labels d-flex justify-content-between small text-muted">
                                        <span>简单</span>
                                        <span>中等</span>
                                        <span>困难</span>
                                    </div>
                                    <div class="progress" style="height: 8px;">
                                        <div id="difficultyProgress" class="progress-bar bg-warning"
                                             role="progressbar" style="width: 0%"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 分数预览 -->
                    <div id="scorePreview" class="score-preview">
                        <div class="score-display">
                            <div class="score-value text-muted" id="scoreValue">0</div>
                            <div class="score-max" id="scoreMax">满分: 0分</div>
                            <div class="score-percentage" id="scorePercentage">得分率: 0%</div>
                            <div class="score-percentage" id="scoreLevel">等级: 未计算</div>
                        </div>
                    </div>
                </div>

                <!-- 考试状态部分 -->
                <div class="form-section analysis-card">
                    <div class="section-header">
                        <div class="section-icon analysis">
                            <i class="fas fa-chart-bar"></i>
                        </div>
                        <h3 class="section-title">考试状态</h3>
                    </div>

                    <div class="form-grid">
                        <div class="form-group">
                            <label for="{{ form.exam_status.id_for_label }}" class="form-label">
                                <i class="fas fa-heartbeat me-2"></i>考试状态
                            </label>
                            {{ form.exam_status }}
                            <div class="form-text">考试时的身体和精神状态</div>
                        </div>

                        <div class="form-group">
                            <label for="{{ form.time_management.id_for_label }}" class="form-label">
                                <i class="fas fa-hourglass-half me-2"></i>时间管理
                            </label>
                            {{ form.time_management }}
                            <div class="form-text">考试时间安排情况</div>
                            <div class="mt-2">
                                <span id="timeManagementIndicator" class="badge bg-secondary">未选择</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 失分细则部分 -->
                <div class="form-section loss-detail-section">
                    <div class="section-header">
                        <div class="section-icon loss">
                            <i class="fas fa-clipboard-list"></i>
                        </div>
                        <h3 class="section-title">失分细则</h3>
                    </div>

                    {% if is_edit %}
                        <!-- 编辑模式：显示失分明细管理链接 -->
                        <div class="alert alert-info">
                            <div class="d-flex align-items-center justify-content-between">
                                <div>
                                    <i class="fas fa-info-circle me-2"></i>
                                    <strong>提示：</strong> 失分细则需要在成绩详情页面进行管理
                                </div>
                                <a href="{% url 'score:score_detail' pk=exam_record.pk %}"
                                   class="btn btn-sm btn-primary">
                                    <i class="fas fa-external-link-alt me-1"></i>管理失分明细
                                </a>
                            </div>
                        </div>

                        <!-- 显示现有失分明细统计 -->
                        {% with loss_details=exam_record.loss_details.all %}
                            {% if loss_details %}
                                <div class="current-loss-details">
                                    <h6 class="mb-3">当前失分明细 (共 {{ loss_details|length }} 条):</h6>
                                    <div class="loss-details-list">
                                        {% for detail in loss_details %}
                                            <div class="loss-detail-item">
                                                <span class="badge bg-danger me-2">-{{ detail.points }}分</span>
                                                <span class="me-2">{{ detail.get_loss_type_display }}</span>
                                                {% if detail.question_number %}
                                                    <small class="text-muted">题号: {{ detail.question_number }}</small>
                                                {% endif %}
                                            </div>
                                        {% endfor %}
                                    </div>
                                </div>
                            {% else %}
                                <div class="text-center text-muted py-4">
                                    <i class="fas fa-clipboard-list fa-2x mb-2"></i>
                                    <p>暂无失分明细记录</p>
                                    <small>可在成绩详情页面添加失分明细</small>
                                </div>
                            {% endif %}
                        {% endwith %}

                    {% else %}
                        <!-- 添加模式：提示保存后添加 -->
                        <div class="alert alert-info">
                            <div class="d-flex align-items-center">
                                <i class="fas fa-info-circle me-2"></i>
                                <div>
                                    <strong>提示：</strong> 失分细则需要在保存成绩记录后，在成绩详情页面进行添加和管理。
                                </div>
                            </div>
                        </div>

                        <div class="text-center text-muted py-4">
                            <i class="fas fa-clipboard-list fa-2x mb-2"></i>
                            <p>保存成绩后可添加失分明细</p>
                            <small>请在保存成绩后，到成绩详情页面添加详细的失分记录</small>
                        </div>
                    {% endif %}
                </div>

                <!-- 表单验证错误 -->
                {% if form.non_field_errors %}
                    <div class="alert alert-danger">
                        <h6 class="alert-heading">
                            <i class="fas fa-exclamation-triangle me-2"></i>表单错误
                        </h6>
                        <ul class="mb-0">
                            {% for error in form.non_field_errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    </div>
                {% endif %}

                <!-- 表单操作 -->
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary-custom" id="submitBtn">
                        <i class="fas {% if is_edit %}fa-save{% else %}fa-plus{% endif %} me-2"></i>
                        {% if is_edit %}保存修改{% else %}保存成绩记录{% endif %}
                    </button>

                    {% if not is_edit %}
                        <a href="{% url 'score:score_add_multiple' %}" class="btn btn-outline-custom">
                            <i class="fas fa-layer-group me-2"></i>批量添加
                        </a>
                    {% endif %}

                    <a href="

                            {% if is_edit %}{% if is_admin %}{% url 'score:score_list' %}{% else %}{% url 'score:score_detail' pk=exam_record.pk %}{% endif %}{% else %}{% url 'score:score_list' %}{% endif %}"
                       class="btn btn-outline-custom">
                        <i class="fas fa-times me-2"></i>取消
                    </a>
                </div>
            </form>
        {% endif %}
    </div>
{% endblock %}